Allow adjustment of the size of TPM transfer buffers
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 3 Oct 2005 14:05:37 +0000 (15:05 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 3 Oct 2005 14:05:37 +0000 (15:05 +0100)
to the size that a lower-layer driver supports.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
linux-2.6-xen-sparse/drivers/char/tpm/tpm_nopci.c
linux-2.6-xen-sparse/drivers/char/tpm/tpm_nopci.h
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c

index eca3aa7804947e161acd2679aea610b9f4f9bab5..872cf33e43e3acd077c8225516b2b63de244d2b5 100644 (file)
@@ -30,7 +30,8 @@
 
 enum {
        TPM_MINOR = 224,        /* officially assigned */
-       TPM_BUFSIZE = 2048,
+       TPM_MIN_BUFSIZE = 2048,
+       TPM_MAX_BUFSIZE = 65536,
        TPM_NUM_DEVICES = 256,
        TPM_NUM_MASK_ENTRIES = TPM_NUM_DEVICES / (8 * sizeof(int))
 };
@@ -63,7 +64,7 @@ static void user_reader_timeout(unsigned long ptr)
 
        down(&chip->buffer_mutex);
        atomic_set(&chip->data_pending, 0);
-       memset(chip->data_buffer, 0, TPM_BUFSIZE);
+       memset(chip->data_buffer, 0, chip->vendor->buffersize);
        up(&chip->buffer_mutex);
 }
 
@@ -458,7 +459,8 @@ int tpm_open(struct inode *inode, struct file *file)
 
        spin_unlock(&driver_lock);
 
-       chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
+       chip->data_buffer = kmalloc(chip->vendor->buffersize * sizeof(u8),
+                                   GFP_KERNEL);
        if (chip->data_buffer == NULL) {
                chip->num_opens--;
                put_device(chip->dev);
@@ -507,8 +509,8 @@ ssize_t tpm_write(struct file * file, const char __user * buf,
 
        down(&chip->buffer_mutex);
 
-       if (in_size > TPM_BUFSIZE)
-               in_size = TPM_BUFSIZE;
+       if (in_size > chip->vendor->buffersize)
+               in_size = chip->vendor->buffersize;
 
        if (copy_from_user
            (chip->data_buffer, (void __user *) buf, in_size)) {
@@ -517,7 +519,9 @@ ssize_t tpm_write(struct file * file, const char __user * buf,
        }
 
        /* atomic tpm command send and result receive */
-       out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
+       out_size = tpm_transmit(chip,
+                               chip->data_buffer,
+                               chip->vendor->buffersize);
 
        atomic_set(&chip->data_pending, out_size);
        up(&chip->buffer_mutex);
@@ -667,6 +671,12 @@ int tpm_register_hardware_nopci(struct device *dev,
 
        chip->vendor = entry;
 
+       if (entry->buffersize < TPM_MIN_BUFSIZE) {
+               entry->buffersize = TPM_MIN_BUFSIZE;
+       } else if (entry->buffersize > TPM_MAX_BUFSIZE) {
+               entry->buffersize = TPM_MAX_BUFSIZE;
+       }
+
        chip->dev_num = -1;
 
        for (i = 0; i < TPM_NUM_MASK_ENTRIES; i++)
index a4d1cc32cb3d1a62961f3b6ab6a2b708f0ae8ee0..e1988549c68d19d06deff78f551e3c3fdcc8f869 100644 (file)
@@ -62,6 +62,7 @@ struct tpm_vendor_specific {
        u8 req_complete_val;
        u8 req_canceled;
        u16 base;               /* TPM base address */
+       u32 buffersize;         /* The device's requested buffersize */
 
        int (*recv) (struct tpm_chip *, u8 *, size_t);
        int (*send) (struct tpm_chip *, u8 *, size_t);
index fc6d1807b6d9bf799bd1f71f172a232b02ed1ac9..2dcb31b8574014f95eb4caa80f7dd16c4be312a3 100644 (file)
@@ -445,6 +445,7 @@ static struct tpm_vendor_specific tpm_xen = {
        .base = 0,
        .attr = TPM_DEVICE_ATTRS,
        .miscdev.fops = &tpm_xen_ops,
+       .buffersize = 64 * 1024,
 };
 
 static struct device tpm_device = {
@@ -477,6 +478,8 @@ static int __init init_xen(void)
                return rc;
        }
 
+       tpm_xen.buffersize = tpmfe.max_tx_size;
+
        if ((rc = tpm_register_hardware_nopci(&tpm_device, &tpm_xen)) < 0) {
                device_unregister(&tpm_device);
                tpm_fe_unregister_receiver();